
Partial Class SQFunctionD
    Inherits System.Web.UI.Page

    Private Const Q As String = Chr(34)

    Private moServer As SQLAutoDocLib.Server = Nothing
    Private moDatabase As SQLAutoDocLib.Database = Nothing
    Private moOwner As SQLAutoDocLib.Login = Nothing
    Private moFunction As SQLAutoDocLib.Function = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sSID As String
        Dim sDID As String
        Dim sOID As String
        Dim sREV As String = ""
        Dim sIsFramed As String = ""

        If IsPostBack = False Then
            sSID = Request.QueryString("S")
            sDID = Request.QueryString("D")
            sOID = Request.QueryString("O")
            sREV = Request.QueryString("R")
            sIsFramed = Request.QueryString("F")

            hidSID.Value = sSID
            hidDID.Value = sDID
            hidOID.Value = sOID
            hidRID.Value = sREV
        Else
            hidRID.Value = Request.Form("cmbRev")
            sREV = Request.Form("cmbRev")

            sSID = hidSID.Value
            sDID = hidDID.Value
            sOID = hidOID.Value
            sREV = cmbRev.Value
        End If

        moServer = New SQLAutoDocLib.Server(sSID)
        moServer.Load()

        moDatabase = New SQLAutoDocLib.Database(sDID)
        moDatabase.Load()

        If Not IsNumeric(sREV) Then
            moFunction = New SQLAutoDocLib.Function(sOID)
        Else
            moFunction = New SQLAutoDocLib.Function(sOID, sREV)
        End If
        moFunction.Load()

        moOwner = New SQLAutoDocLib.Login(moFunction.OwnerID)
        moOwner.Load()

        If IsPostBack = False Then
            If Not IsNumeric(sIsFramed) Then
                Dim oRevFactory As New SQLAutoDocLib.Function_Factory
                Dim oList As ArrayList = oRevFactory.GetAllFunctionRevs(moFunction.ID)
                For Each oRev As SQLAutoDocLib.Function In oList
                    cmbRev.Items.Add(New ListItem(oRev.RevDate, oRev.RevID))
                Next

                hidRID.Value = oList.Item(0).RevID
                txtDesc.Value = moFunction.Desc

            Else
                cmbRev.Visible = False
                lblRev.Visible = True

                lblRev.InnerText = moFunction.CreateDate
                txtDesc.Visible = False

                If moFunction.Desc > "" Then
                    lblDesc.Style.Add("border", "solid 1px grey")

                    lblDesc.InnerHtml = "<pre>" & moFunction.Desc & "</pre>"
                Else
                    lblDesc.Style.Add("height", "1px")
                End If
            End If

        ElseIf hidToolbarAction.Value = "refresh" Then
            txtDesc.Value = moFunction.Desc

        ElseIf hidToolbarAction.Value = "save" Then
            moFunction.Desc = txtDesc.Value
            moFunction.Save()

            Dim oExtendedProperties As New SQLAutoDocLib.ExtendedProperties
            oExtendedProperties.UpdateFunctionDescription(moFunction.DatabaseID, moFunction.ID, txtDesc.Value)

        ElseIf hidToolbarAction.Value = "back" Then
            Server.Transfer("SQFunctionE.aspx?S=" & hidSID.Value & "&D=" & hidDID.Value)
        End If
    End Sub

    Protected Sub ShowFunctionDetail()
        Dim lsProcID As Long = hidOID.Value
        Dim lRevID As Long = hidRID.Value

        Dim oViewReporter As New SQLAutoDocLib.Rpt_Functions
        oViewReporter.ShowFunctionDetail(lsProcID, lRevID)
    End Sub

    Protected Function FormLabel() As String
        Return "Function: " & moOwner.Login & "." & moFunction.Name
    End Function

    Protected Function ScanMode() As String
        Return "Function"
    End Function

    Protected Function EditMode() As String
        Return "Function"
    End Function

    Protected Function ServerID() As String
        Return moServer.ID
    End Function

    Protected Function DatabaseID() As String
        Return moDatabase.ID
    End Function

    Protected Function ObjectID() As String
        Return moFunction.ID
    End Function

    Protected Function ObjectRev() As String
        Return moFunction.RevID
    End Function
End Class
